package com.workpaper.app.utils.resource;

import java.io.Closeable;
import java.io.IOException;
import java.util.Enumeration;
import java.util.ResourceBundle;

import com.workpaper.app.cache.resource.ViewInfoCache;

/**
 * 资源工具
 * @author hp
 *
 */
public class ResourceUtils {
	/**
	 * 加载properties文件内容
	 * @param path 文件相对于src目录路径
	 */
	public static void loadResource(String path) {
		ResourceBundle resource = ResourceBundle.getBundle(path);
		Enumeration<String> keys = resource.getKeys();
		while(keys.hasMoreElements()) {
			String key = keys.nextElement();
			ViewInfoCache.push(key, resource.getString(key));
		}
	}
	
	
	/**
	 * 关闭资源
	 * @param resource  Closeable
	 */
	public static void closeResource(Closeable resource) {
		try {
			if(resource != null) {
				resource.close();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
